package com.example.demo.order.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @ClassName PaymentResponse
 * @Description 支付响应结果
 * @Author MingChang.Wei
 * @Date 2025/9/26
 **/
@Data
@Schema(description = "支付响应结果")
public class PaymentResponse {
    
    @Schema(description = "支付是否成功", example = "true")
    private Boolean success;
    
    @Schema(description = "支付流水号", example = "PAY202509260001")
    private String paymentId;
    
    @Schema(description = "订单号", example = "ORD202509260001")
    private String orderNo;
    
    @Schema(description = "支付金额", example = "99.99")
    private BigDecimal amount;
    
    @Schema(description = "支付状态", example = "PAID", allowableValues = {"PENDING", "PAID", "FAILED", "CANCELLED"})
    private String status;
    
    @Schema(description = "支付方式", example = "ALIPAY")
    private String paymentMethod;
    
    @Schema(description = "第三方支付单号", example = "2023092622001234567890")
    private String thirdPartyPaymentId;
    
    @Schema(description = "支付时间")
    private LocalDateTime paymentTime;
    
    @Schema(description = "支付二维码URL", example = "https://qr.alipay.com/bax08888")
    private String qrCodeUrl;
    
    @Schema(description = "支付跳转URL", example = "https://openapi.alipay.com/gateway.do")
    private String paymentUrl;
    
    @Schema(description = "错误码", example = "0000")
    private String errorCode;
    
    @Schema(description = "错误信息", example = "支付成功")
    private String errorMessage;
    
    @Schema(description = "过期时间")
    private LocalDateTime expireTime;
    
    @Schema(description = "支付令牌", example = "token_123456789")
    private String paymentToken;
    
    // 静态工厂方法
    public static PaymentResponse success(String paymentId, String orderNo, BigDecimal amount) {
        PaymentResponse response = new PaymentResponse();
        response.setSuccess(true);
        response.setPaymentId(paymentId);
        response.setOrderNo(orderNo);
        response.setAmount(amount);
        response.setStatus("PAID");
        response.setPaymentTime(LocalDateTime.now());
        response.setErrorCode("0000");
        response.setErrorMessage("支付成功");
        return response;
    }
    
    public static PaymentResponse pending(String paymentId, String orderNo, BigDecimal amount, String qrCodeUrl) {
        PaymentResponse response = new PaymentResponse();
        response.setSuccess(false);
        response.setPaymentId(paymentId);
        response.setOrderNo(orderNo);
        response.setAmount(amount);
        response.setStatus("PENDING");
        response.setQrCodeUrl(qrCodeUrl);
        response.setExpireTime(LocalDateTime.now().plusMinutes(15)); // 15分钟过期
        response.setErrorCode("0001");
        response.setErrorMessage("等待支付");
        return response;
    }
    
    public static PaymentResponse failed(String orderNo, String errorCode, String errorMessage) {
        PaymentResponse response = new PaymentResponse();
        response.setSuccess(false);
        response.setOrderNo(orderNo);
        response.setStatus("FAILED");
        response.setErrorCode(errorCode);
        response.setErrorMessage(errorMessage);
        return response;
    }
}
